home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / AOCE Utilities / AOCE Snippits / GetUserIdentity.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-25  |  2.5 KB  |  92 lines  |  [TEXT/KAHL]

  1. /*
  2.  * GetUserIdentity.c
  3.  *
  4.  * Copyright © 1993, Apple Computer Inc.
  5.  * All rights reserved.
  6.  *
  7.  * This function initializes AOCE in an application context.
  8.  * If it returns successfully, it stores the user identity
  9.  * in the supplied variable.
  10.  */
  11.  
  12. #include <GestaltEqu.h>
  13. #include <OCE.h>
  14. #include <OCEAuthDir.h>
  15. #include <OCEErrors.h>
  16. #include <OCEStandardDirectory.h>
  17. #define TRUE        1
  18. #define FALSE        0
  19.  
  20. OSErr                        GetUserIdentity(
  21.         AuthIdentity            *userIdentity
  22.     );
  23.  
  24. /*
  25.  * Get the user's local identity. On success, the identity is
  26.  * stored in the specified location. The only expected error
  27.  * is userCanceledErr, which probably means "just exit the
  28.  * application." Other errors should be displayed.
  29.  */
  30. OSErr
  31. GetUserIdentity(
  32.         AuthIdentity            *userIdentity
  33.     )
  34. {
  35.         long                    gestaltResponse;
  36.         SDPIdentityKind            selectedKind;
  37.         AuthParamBlock            authParamBlock;
  38.         OSErr                    status;
  39.         
  40.         /*
  41.          * Make sure this Macintosh supports AOCE.
  42.          */
  43.         status = Gestalt(gestaltOCEToolboxAttr, &gestaltResponse);
  44.         if (status == noErr
  45.          && (gestaltResponse & gestaltOCETBAvailable) == 0)
  46.             status = kOCEToolboxNotOpen;
  47.         if (status == noErr) {
  48.             /*
  49.              * OCE Setup: get the user's local authentication identity. If it's
  50.              * already set, we can do this silently. If it's not set (the system
  51.              * has just been started), we'll prompt for the user's identity
  52.              * and password.
  53.              *
  54.              * The only expected error is "Cancel" from SDPPromptForIdentity.
  55.              */
  56.             status = AuthGetLocalIdentity(
  57.                     &authParamBlock,            /* Parameter block                    */
  58.                     FALSE                        /* Synchronous                        */
  59.                 );
  60.         }
  61.         if (status == noErr) {
  62.             /*
  63.              * The user identity has already been specified.
  64.              */
  65.             *userIdentity = authParamBlock.getLocalIdentityPB.theLocalIdentity;
  66.         }
  67.         else if (status == kOCELocalAuthenticationFail) {
  68.             /*
  69.              * No user identity has been specified. Ask for the user to specify
  70.              * the local identity.
  71.              */
  72.             status = SDPPromptForID(
  73.                     userIdentity,            /* AuthIdentity        *id                */ 
  74.                     NULL,                    /* Default guest prompt                */
  75.                     NULL,                    /* Default specific prompt            */
  76.                     NULL,                    /* Default local prompt                */
  77.                     NULL,                    /* RString            *recordType        */
  78.                     (                        /* SDPIdentityKind    permittedKinds    */
  79.                         kSDPLocalIdentityMask        /* Local identity            */
  80.                         | kSDPSpecificIdentityMask    /* or specific identity        */
  81.                     ),
  82.                     &selectedKind,            /* SDPIdentityKind    *selectedKind    */
  83.                     NULL,                    /* RecordID            *loginFilter    */
  84.                     0                        /* SDPLoginFilterKind filterKind    */                        
  85.                 );
  86.         }
  87.         else {
  88.             /* AuthGetLocalIdentity is very unhappy. */
  89.         }
  90.         return (status);
  91. }
  92.